/*
 * Topscores.java
 *
 * Created on 19 mei 2008, 17:27
 */
package client.gui;

import client.communication.ClientCommunication;
import data.Gameroom;
import data.SpelScore;
import java.awt.Cursor;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

/**
 *
 * @author  Liesbeth
 */
public class Topscores extends javax.swing.JFrame {

    private JLabel[] namen = new JLabel[12];
    private JLabel[] scores = new JLabel[12];
    private JLabel[] gewonnen = new JLabel[12];
    private JLabel[] verloren = new JLabel[12];
    private Gameroom.Gametype gametype;
    private String nickname;

    /** Creates new form Topscores */
    public Topscores(String nickname) {
        initComponents();
        this.setNickname(nickname);
        ClientCommunication.getInstance().setTopscoreGui(this);
        for (int i = 0; i < 12; i++) {
            if (i == 0) {
                namen[i] = new JLabel("Naam");
                scores[i] = new JLabel("Score");
                gewonnen[i] = new JLabel("Gewonnen");
                verloren[i] = new JLabel("Verloren");
            } else if (i == 11) {
                namen[i] = new JLabel("");
                scores[i] = new JLabel("");
                gewonnen[i] = new JLabel("");
                verloren[i] = new JLabel("");
            } else {
                namen[i] = new JLabel("");
                scores[i] = new JLabel("0");
                gewonnen[i] = new JLabel("0");
                verloren[i] = new JLabel("0");
            }

            namen[i].setHorizontalAlignment(SwingConstants.LEFT);
            scores[i].setHorizontalAlignment(SwingConstants.CENTER);
            gewonnen[i].setHorizontalAlignment(SwingConstants.CENTER);
            verloren[i].setHorizontalAlignment(SwingConstants.CENTER);

            pnlNaam.add(namen[i]);
            pnlScore.add(scores[i]);
            pnlGewonnen.add(gewonnen[i]);
            pnlVerloren.add(verloren[i]);
        }
        bepaalTopscores();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlTopscores = new javax.swing.JPanel();
        pnlNummer = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbl1 = new javax.swing.JLabel();
        lbl2 = new javax.swing.JLabel();
        lbl3 = new javax.swing.JLabel();
        lbl4 = new javax.swing.JLabel();
        lbl5 = new javax.swing.JLabel();
        lbl6 = new javax.swing.JLabel();
        lbl7 = new javax.swing.JLabel();
        lbl8 = new javax.swing.JLabel();
        lbl9 = new javax.swing.JLabel();
        lbl10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        pnlScores = new javax.swing.JPanel();
        pnlScore = new javax.swing.JPanel();
        pnlGewonnen = new javax.swing.JPanel();
        pnlVerloren = new javax.swing.JPanel();
        pnlNaam = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        cboSpellen = new javax.swing.JComboBox();
        btnScores = new javax.swing.JButton();

        setTitle("Topscores");
        setResizable(false);

        pnlTopscores.setPreferredSize(new java.awt.Dimension(400, 300));
        pnlTopscores.setLayout(new java.awt.BorderLayout());

        pnlNummer.setLayout(new java.awt.GridLayout(12, 0, 10, 0));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        pnlNummer.add(jLabel1);

        lbl1.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl1.setText("1.");
        pnlNummer.add(lbl1);

        lbl2.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl2.setText("2.");
        pnlNummer.add(lbl2);

        lbl3.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl3.setText("3.");
        pnlNummer.add(lbl3);

        lbl4.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl4.setText("4.");
        pnlNummer.add(lbl4);

        lbl5.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl5.setText("5.");
        pnlNummer.add(lbl5);

        lbl6.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl6.setText("6.");
        pnlNummer.add(lbl6);

        lbl7.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl7.setText("7.");
        pnlNummer.add(lbl7);

        lbl8.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl8.setText("8.");
        pnlNummer.add(lbl8);

        lbl9.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl9.setText("9.");
        pnlNummer.add(lbl9);

        lbl10.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbl10.setText("10.");
        pnlNummer.add(lbl10);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
        pnlNummer.add(jLabel12);

        pnlTopscores.add(pnlNummer, java.awt.BorderLayout.WEST);

        pnlScores.setLayout(new java.awt.GridLayout(1, 3, 0, 5));

        pnlScore.setLayout(new java.awt.GridLayout(12, 0, 10, 0));
        pnlScores.add(pnlScore);

        pnlGewonnen.setLayout(new java.awt.GridLayout(12, 0, 10, 0));
        pnlScores.add(pnlGewonnen);

        pnlVerloren.setLayout(new java.awt.GridLayout(12, 0, 10, 0));
        pnlScores.add(pnlVerloren);

        pnlTopscores.add(pnlScores, java.awt.BorderLayout.EAST);

        pnlNaam.setLayout(new java.awt.GridLayout(12, 0, 10, 0));
        pnlTopscores.add(pnlNaam, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnlTopscores, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.BorderLayout());

        cboSpellen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scrabble", "Boggle", "Galgje" }));
        jPanel1.add(cboSpellen, java.awt.BorderLayout.CENTER);

        btnScores.setText("Scores ophalen");
        btnScores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnScoresActionPerformed(evt);
            }
        });
        jPanel1.add(btnScores, java.awt.BorderLayout.EAST);

        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents
    private void btnScoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScoresActionPerformed
        bepaalTopscores();
    }//GEN-LAST:event_btnScoresActionPerformed

    private void bepaalTopscores() {
        getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (cboSpellen.getSelectedItem().equals("Scrabble")) {
            gametype = Gameroom.Gametype.SCRABBLE;
        } else if (cboSpellen.getSelectedItem().equals("Boggle")) {
            gametype = Gameroom.Gametype.BOGGLE;
        } else if (cboSpellen.getSelectedItem().equals("Galgje")) {
            gametype = Gameroom.Gametype.GALGJE;
        }
        ClientCommunication.getInstance().bepaalTopscores(gametype, nickname);
    }

    public void scoresBepaald(SpelScore[] topscores) {
        for (int i = 0; i < 10; i++) {
            // in het begin 1 leeg label laten staan
            if (topscores[i] != null) {
                namen[i + 1].setText(topscores[i].getNickname());
                switch (gametype) {
                    case GALGJE:
                        scores[i + 1].setText("" + topscores[i].getScore().getGalgjeScore());
                        gewonnen[i + 1].setText("" + topscores[i].getScore().getGalgjeGewonnen());
                        verloren[i + 1].setText("" + topscores[i].getScore().getGalgjeVerloren());
                        break;
                    case BOGGLE:
                        scores[i + 1].setText("" + topscores[i].getScore().getBoggleScore());
                        gewonnen[i + 1].setText("" + topscores[i].getScore().getBoggleGewonnen());
                        verloren[i + 1].setText("" + topscores[i].getScore().getBoggleVerloren());
                        break;
                    case SCRABBLE:
                        scores[i + 1].setText("" + topscores[i].getScore().getScrabbleScore());
                        gewonnen[i + 1].setText("" + topscores[i].getScore().getScrabbleGewonnen());
                        verloren[i + 1].setText("" + topscores[i].getScore().getScrabbleVerloren());
                        break;
                }
            }

        }
        getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnScores;
    private javax.swing.JComboBox cboSpellen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lbl10;
    private javax.swing.JLabel lbl2;
    private javax.swing.JLabel lbl3;
    private javax.swing.JLabel lbl4;
    private javax.swing.JLabel lbl5;
    private javax.swing.JLabel lbl6;
    private javax.swing.JLabel lbl7;
    private javax.swing.JLabel lbl8;
    private javax.swing.JLabel lbl9;
    private javax.swing.JPanel pnlGewonnen;
    private javax.swing.JPanel pnlNaam;
    private javax.swing.JPanel pnlNummer;
    private javax.swing.JPanel pnlScore;
    private javax.swing.JPanel pnlScores;
    private javax.swing.JPanel pnlTopscores;
    private javax.swing.JPanel pnlVerloren;
    // End of variables declaration//GEN-END:variables
    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
}
